package cn.powerone.scm.mapper;

import java.util.Date;
import java.util.List;
import cn.powerone.scm.domain.ScmCustomer;
import cn.powerone.scm.domain.ScmCustomerContacts;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

/**
 * 客户Mapper接口
 * 
 * @author PowerOne
 * @date 2025-06-23
 */
public interface ScmCustomerMapper 
{
    /**
     * 查询客户
     * 
     * @param id 客户主键
     * @return 客户
     */
    public ScmCustomer selectScmCustomerById(Long id);

    /**
     * 查询客户列表
     * 
     * @param scmCustomer 客户
     * @return 客户集合
     */
    public List<ScmCustomer> selectScmCustomerList(ScmCustomer scmCustomer);

    /**
     * 新增客户
     * 
     * @param scmCustomer 客户
     * @return 结果
     */
    public int insertScmCustomer(ScmCustomer scmCustomer);

    /**
     * 修改客户
     * 
     * @param scmCustomer 客户
     * @return 结果
     */
    public int updateScmCustomer(ScmCustomer scmCustomer);

    /**
     * 删除客户
     * 
     * @param id 客户主键
     * @return 结果
     */
    public int deleteScmCustomerById(Long id);

    /**
     * 批量删除客户
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteScmCustomerByIds(Long[] ids);

    /**
     * 批量删除联系人
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteScmCustomerContactsByCustomerIds(Long[] ids);
    
    /**
     * 批量新增联系人
     * 
     * @param scmCustomerContactsList 联系人列表
     * @return 结果
     */
    public int batchScmCustomerContacts(List<ScmCustomerContacts> scmCustomerContactsList);
    

    /**
     * 通过客户主键删除联系人信息
     * 
     * @param id 客户ID
     * @return 结果
     */
    public int deleteScmCustomerContactsByCustomerId(Long id);

    /**
     * 查询指定日期所在月份的客户数量
     * 
     * @param yesterday 指定日期
     * @return 客户数量
     */
    @Select("SELECT COUNT(*) FROM scm_customer WHERE YEAR(create_time) = YEAR(#{yesterday}) AND MONTH(create_time) = MONTH(#{yesterday})")
    @Options(useCache = false, flushCache = Options.FlushCachePolicy.TRUE)
    public int selectCustomerCountByMonth(Date yesterday);

    /**
     * 查询指定日期所在年份的客户数量
     * 
     * @param yesterday 指定日期
     * @return 客户数量
     */
    @Select("SELECT COUNT(*) FROM scm_customer WHERE YEAR(create_time) = YEAR(#{yesterday})")
    @Options(useCache = false, flushCache = Options.FlushCachePolicy.TRUE)
    public int selectCustomerCountByYear(Date yesterday);

    /**
     * 查询所有客户数量
     * 
     * @return 客户数量
     */
    @Select("SELECT COUNT(*) FROM scm_customer")
    @Options(useCache = false, flushCache = Options.FlushCachePolicy.TRUE)
    public int selectCustomerCountAll();
}